package com.laoniu.controller.base;

import com.laoniu.annotation.OperateLog;
import com.laoniu.biz.base.BaseSupplierBiz;
import com.laoniu.dto.RestResult;
import com.laoniu.dto.request.BaseSupplierRequestDto;
import com.laoniu.dto.response.BaseSupplierDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 供应商表 前端控制器
 * </p>
 *
 * @author lxl
 * @since 2023-12-17
 */
@RestController
@RequestMapping("/base/supplier")
public class BaseSupplierController {

    @Autowired
    private BaseSupplierBiz supplierBiz;

    /**
     * 分页查询
     * @param requestDto
     * @return
     */
    @PostMapping("list")
    public RestResult list(@RequestBody BaseSupplierRequestDto requestDto){
        return RestResult.success(supplierBiz.pageList(requestDto));
    }

    /**
     * 新增供应商
     * @param dto
     * @return
     */
    @PostMapping("add")
    @OperateLog(bizName = "供应商信息", operateType = "新增供应商", operateDesc = "管理后台添加供应商")
    public RestResult add(@RequestBody BaseSupplierDto dto){
        supplierBiz.addSupplier(dto);
        return RestResult.success();
    }
    /**
     * 修改供应商
     * @param dto
     * @return
     */
    @PostMapping("update")
    @OperateLog(bizName = "供应商信息", operateType = "修改供应商", operateDesc = "管理后台修改供应商")
    public RestResult update(@RequestBody BaseSupplierDto dto){
        supplierBiz.updateSupplier(dto);
        return RestResult.success();
    }

    /**
     * 删除供应商
     * @param dto
     * @return
     */
    @PostMapping("delete")
    @OperateLog(bizName = "供应商信息", operateType = "删除供应商", operateDesc = "管理后台删除供应商")
    public RestResult delete(@RequestBody BaseSupplierDto dto){
        return supplierBiz.delete(dto.getId());
    }

    @GetMapping("allSupplier")
    public RestResult allSupplier(){
        return RestResult.success(supplierBiz.allSupplier());
    }
}
